﻿using System.ComponentModel.DataAnnotations;

namespace Forum.Model.Validation
{
    public class ChineseAttribute : ValidationAttribute
    {
        protected static string error = "{0}只能是汉字";
        protected override ValidationResult? IsValid(object? value, ValidationContext validationContext)
        {
            var fildName = validationContext.DisplayName;

            if (FormatValidation.IsChinese(value as string))
                return ValidationResult.Success;

            return new ValidationResult(ErrorMessage ?? string.Format(error, fildName));
        }
    }
}